package com.bsoft.exchange.util;

import com.bsoft.exchange.domain.InspectionListDomain;
import com.bsoft.exchange.domain.MicrobiologyReportDomain;
import com.bsoft.exchange.domain.RegularReportDomain;

import javax.xml.bind.JAXBContext;
import javax.xml.bind.JAXBException;
import javax.xml.bind.Unmarshaller;
import java.io.StringReader;

public class JaxbUtil {

    public static <T> T xmlToBean(String xmlStr,Class<T> clazz){
        try {

            JAXBContext jaxbContext = JAXBContext.newInstance(clazz);
            Unmarshaller unmarshaller = jaxbContext.createUnmarshaller();
            return (T) unmarshaller.unmarshal(new StringReader(xmlStr));
        } catch (JAXBException e) {
            e.printStackTrace();
        }
        return null;
    }

    public static void main(String[] args) {
        String xml = "<LabReport><DCId>3d46cac7b2c1455780a20006446</DCId><SampleNo>20170909DAE020</SampleNo><BarcodeNo>201709099432301A</BarcodeNo><AuthorOrganization>46821120-9</AuthorOrganization><PatientType DisplayName=\"住院\">04</PatientType><ClinicId>3252413</ClinicId><HospizationId>326547</HospizationId><Name>王平</Name><Sex DisplayName=\"男性\">1</Sex><Age>24</Age><DeptName>肝胆外科</DeptName><WardName>东区普外科</WardName><DiagnoseName>急性阑尾炎</DiagnoseName><LabOrdersItemName>检验名称</LabOrdersItemName><RequestTime>20130116T112855</RequestTime><RequestDoctor DisplayName=\"王珣\">0001</RequestDoctor><SampleTypeName>穿刺液</SampleTypeName><SampleExecuteTime>20130116T112855</SampleExecuteTime><SampleReceiveTime>20130116T112855</SampleReceiveTime><ReportDateTime>20130116T112855</ReportDateTime><ReportDoctor>王珣</ReportDoctor><ReportReviewTime>20130116T112855</ReportReviewTime><ReportReviewDoctor>王珣</ReportReviewDoctor><ReportStatus>2</ReportStatus><ReportType>5</ReportType><BioResult><BioName>链球菌</BioName><BioQuantity>50</BioQuantity><BioUnit>细菌数量单位</BioUnit><BioNO>2</BioNO><Remarks>备注信息</Remarks><AntiResult><AntiName>H</AntiName><Method>1</Method><KBResult>KB结果</KBResult><MICResult>MIC结果</MICResult><ETESTResult>ETEST结果</ETESTResult><ResultUnit_Anti>结果单位</ResultUnit_Anti><AntiResult>耐药性结果</AntiResult><PrintOrder>打印次序</PrintOrder></AntiResult><AntiResult><AntiName>H</AntiName><Method>1</Method><KBResult>KB结果</KBResult><MICResult>MIC结果</MICResult><ETESTResult>ETEST结果</ETESTResult><ResultUnit_Anti>结果单位</ResultUnit_Anti><AntiResult>耐药性结果</AntiResult><PrintOrder>打印次序</PrintOrder></AntiResult></BioResult><BioResult><BioName>链球菌</BioName><BioQuantity>50</BioQuantity><BioUnit>细菌数量单位</BioUnit><BioNO>2</BioNO><Remarks>备注信息</Remarks><AntiResult><AntiName>H</AntiName><Method>1</Method><KBResult>KB结果</KBResult><MICResult>MIC结果</MICResult><ETESTResult>ETEST结果</ETESTResult><ResultUnit_Anti>结果单位</ResultUnit_Anti><AntiResult>耐药性结果</AntiResult><PrintOrder>打印次序</PrintOrder></AntiResult><AntiResult><AntiName>H</AntiName><Method>1</Method><KBResult>KB结果</KBResult><MICResult>MIC结果</MICResult><ETESTResult>ETEST结果</ETESTResult><ResultUnit_Anti>结果单位</ResultUnit_Anti><AntiResult>耐药性结果</AntiResult><PrintOrder>打印次序</PrintOrder></AntiResult></BioResult></LabReport>";
        MicrobiologyReportDomain microbiologyReportDomain = xmlToBean(xml, MicrobiologyReportDomain.class);
        System.out.println(microbiologyReportDomain);
    }
}
